package com.hzvdvmc.autosale.setting.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hzvdvmc.autosale.R;
import com.hzvdvmc.autosale.common.OnItemClickListener;
import com.hzvdvmc.autosale.setting.bean.AboutStateBean;

import java.util.List;

/**
 * Created by william on 2018/1/11.
 */

public class AboutRvAdapter extends RecyclerView.Adapter<AboutRvAdapter.AboutRvViewHolder> {
    private List<AboutStateBean> dataList;
    private OnItemClickListener onItemClickListener;

    public AboutRvAdapter(List<AboutStateBean> dataList) {
        this.dataList = dataList;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public AboutRvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_about_list, parent, false);
        return new AboutRvViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(AboutRvViewHolder holder, final int position) {
        holder.tvKey.setText(dataList.get(position).getKey());
        holder.tvValue.setText(dataList.get(position).getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onClick(v, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    class AboutRvViewHolder extends RecyclerView.ViewHolder {
        TextView tvKey, tvValue;

        public AboutRvViewHolder(View itemView) {
            super(itemView);
            tvKey = (TextView) itemView.findViewById(R.id.tv_item_key);
            tvValue = (TextView) itemView.findViewById(R.id.tv_item_value);
        }
    }
}
